package com.kws.merchant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.kws.common.core.domain.R;
import com.kws.merchant.domain.*;
import com.kws.merchant.domain.po.*;
import com.kws.merchant.domain.vo.*;
import com.kws.merchant.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : zhangbenting
 * @date : 2024/11/20 14:20
 * @Version: 1.0
 */
@RequestMapping("/userMine")
@RestController
@Api(value = "用户服务-我的", tags = "用户服务-我的")
public class UserMineController {

    @Autowired
    private ShippingAddressService shippingAddressService;
    @Autowired
    private UserRemarkService userRemarkService;
    @Autowired
    private FeedbackMessageService feedbackMessageService;
    @Autowired
    private UserOrderService userOrderService;
    @Autowired
    private UserAuthService userAuthService;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private PowerStationService powerStationService;
    @Autowired
    private PlatformInfoService platformInfoService;

    @ApiOperation("上传文件")
    @PostMapping("/uploadFile")
    public R<UploadVo> uploadFile(@RequestParam("file") MultipartFile file) {
        UploadVo uploadVo = new UploadVo();
        uploadVo.setUrl(merchantService.uploadCompanyFile(file));
        return R.ok(uploadVo);
    }

//    @PostMapping("getContractUserOrder")
//    @ApiOperation(value = "获取服务订单列表")
//    @ApiOperationSupport(order = 1, includeParameters = {
//            "orderInfoPo.id",
//            "orderInfoPo.pageSize",
//            "orderInfoPo.totalPage"
//    })
//    public R<Page<ContractOrderVo>> getContractUserOrder(@RequestBody OrderInfoPo orderInfoPo) {
//        return R.ok(userOrderService.getContractUserOrder(orderInfoPo));
//    }

    @PostMapping("getUserOrderList")
    @ApiOperation("用户获取订单列表")
    @ApiOperationSupport(order = 3, includeParameters = {
            "orderInfoPo.goodName",
            "orderInfoPo.intervalTime",
            "orderInfoPo.isEvaluate",
            "orderInfoPo.type",
            "orderInfoPo.id",
            "orderInfoPo.status",
            "orderInfoPo.pageSize",
            "orderInfoPo.totalPage"
    })
    public R<Page<Order>> getUserOrderList(@RequestBody OrderInfoPo orderInfoPo) {
        return R.ok(userOrderService.getUserOrderList(orderInfoPo));
    }

    @PostMapping("updateUserOrder")
    @ApiOperation("用户修改订单")
    @ApiOperationSupport(order = 3, includeParameters = {
            "orderInfoPo.id",
            "orderInfoPo.shippingAddressId"
    })
    public R<Boolean> updateUserOrder(@RequestBody OrderInfoPo orderInfoPo) {
        return R.ok(userOrderService.updateUserOrder(orderInfoPo));
    }

    @PostMapping("payUserOrder")
    @ApiOperation(value = "用户支付订单")
    public R<String> payUserOrder(@RequestParam Long orderId) {
        return R.ok(userOrderService.payUserOrder(orderId));
    }

    @GetMapping("cancelOrder")
    @ApiOperation(value = "取消订单")
    public R<Boolean> cancelOrder(@RequestParam Long orderId) {
        return R.ok(userOrderService.cancelOrder(orderId));
    }

    @GetMapping("applyRefund")
    @ApiOperation(value = "申请退款")
    public R<Boolean> applyRefund(@RequestParam Long orderId) {
        return R.ok(userOrderService.applyRefund(orderId));
    }

    @PostMapping("userSignContract")
    @ApiOperation(value = "签订合同")
    public R<SignContractVo> userSignContract(@RequestParam Long orderId) {
        return R.ok(userOrderService.userSignContract(orderId));
    }

    @DeleteMapping("deleteOrder")
    @ApiOperation(value = "删除订单")
    public R<Boolean> deleteOrder(@RequestParam Long orderId) {
        return R.ok(userOrderService.deleteOrder(orderId));
    }

    @PostMapping("/addUserRemark")
    @ApiOperation(value = "用户对商品订单评价")
    @ApiOperationSupport(order = 3, includeParameters = {
            "userRemarkPo.orderId",
            "userRemarkPo.goodsType",
            "userRemarkPo.goodsId",
            "userRemarkPo.remark",
            "userRemarkPo.expressPackage",
            "userRemarkPo.deliverySpeed",
            "userRemarkPo.deliveryPersonnel",
            "userRemarkPo.remarkImg",
            "userRemarkPo.starLevel"
    })
    public R<Boolean> addUserRemark(@RequestBody UserRemarkPo userRemarkPo) {
        return R.ok(userRemarkService.addUserRemark(userRemarkPo));
    }

    @PostMapping("/getUserRemarkList")
    @ApiOperation(value = "获取用户评论列表")
    @ApiOperationSupport(order = 4, includeParameters = {
            "userRemarkPo.pageSize",
            "userRemarkPo.totalPage"
    })
    public R<Page<UserRemarkVo>> getUserRemarkList(@RequestBody UserRemarkPo userRemarkPo) {
        return R.ok(userRemarkService.getUserRemarkList(userRemarkPo));
    }

    @GetMapping("/getUserRemarkInfo")
    @ApiOperation(value = "获取用户评论详情")
    public R<List<DeviceRemark>> getUserRemarkInfo(@RequestParam Long goodsId) {
        return R.ok(userRemarkService.getUserRemarkInfo(goodsId));
    }

    @GetMapping("/deleteUserRemark")
    @ApiOperation(value = "删除用户评论")
    public R<Boolean> deleteUserRemark(@RequestParam Long remarkId) {
        return R.ok(userRemarkService.deleteUserRemark(remarkId));
    }

    @ApiOperation("获取用户收货地址列表")
    @PostMapping("/getShipAddressList")
    @ApiOperationSupport(order = 4, includeParameters = {
            "shipAddressPo.pageSize",
            "shipAddressPo.totalPage"
    })
    public R<Page<ShippingAddress>> getShipAddressList(@RequestBody ShipAddressPo shipAddressPo) {
        return R.ok(shippingAddressService.getShipAddressList(shipAddressPo));
    }

    @ApiOperation("新增或修改用户收货地址")
    @PostMapping("/saveOrUpdateShipAddress")
    @ApiOperationSupport(order = 5, includeParameters = {
            "shippingAddress.id",
            "shippingAddress.consignee",
            "shippingAddress.consigneePhone",
            "shippingAddress.addr",
            "shippingAddress.addressInfo",
            "shippingAddress.addressAlias",
            "shippingAddress.isDefault",
            "shippingAddress.addrLabel"
    })
    public R<Boolean> saveOrUpdateShipAddress(@Valid @RequestBody ShippingAddress shippingAddress) {
        return R.ok(shippingAddressService.saveOrUpdateShipAddress(shippingAddress));
    }

    @ApiOperation("删除用户收货地址")
    @PostMapping("/removeShipAddress")
    @ApiOperationSupport(includeParameters = {
            "shipAddressPo.shipAddressIds"
    })
    public R<Boolean> removeShipAddress(@RequestBody @Valid ShipAddressPo shipAddressPo) {
        return R.ok(shippingAddressService.removeShipAddress(shipAddressPo.getShipAddressIds()));
    }

    @PostMapping("/addFeedbackMessage")
    @ApiOperation(value = "新增反馈意见")
    @ApiOperationSupport(order = 7, includeParameters = {
            "feedbackMessagePo.phone",
            "feedbackMessagePo.feedbackMessage",
            "feedbackMessagePo.feedbackImg"
    })
    public R<Boolean> addFeedbackMessage(@RequestBody FeedbackMessagePo feedbackMessagePo) {
        return R.ok(feedbackMessageService.addFeedbackMessage(feedbackMessagePo));
    }

    @PostMapping("/identityAuth")
    @ApiOperation(value = "身份认证")
    public R<Boolean> identityAuth(@RequestBody UserAuthPo userAuthPo) {
        return R.ok(userAuthService.identityAuth(userAuthPo));
    }

    @PostMapping("/updateAccount")
    @ApiOperation(value = "修改账号信息")
    @ApiOperationSupport(order = 8, includeParameters = {
            "accountManagementVo.phone",
            "accountManagementVo.sex",
            "accountManagementVo.headImg"
    })
    public R<Boolean> updateAccount(@Valid @RequestBody AccountManagementVo accountManagementVo) {
        return R.ok(userAuthService.updateAccount(accountManagementVo));
    }

    @PostMapping("/getUserIdentityAuthInfo")
    @ApiOperation(value = "获取用户身份认证信息")
    public R<UserAuthPo> getUserIdentityAuthInfo(@RequestParam Long userId) {
        return R.ok(userAuthService.getUserIdentityAuthInfo(userId));
    }

    @GetMapping("/accountManagement")
    @ApiOperation(value = "账号管理")
    public R<AccountManagementVo> accountManagement() {
        return R.ok(userAuthService.accountManagement());
    }

    @GetMapping("/getPlatformInfo")
    @ApiOperation(value = "获取平台信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "titleName", value = "标题名称(如用户协议)", dataType = "String", required = true),
    })
    public R<PlatformInfoEntity> getPlatformInfo(@RequestParam String titleName) {
        return R.ok(platformInfoService.getPlatformInfo(titleName));
    }

    //通知公告
    //消息统计

    @GetMapping("/getUserMessageCount")
    @ApiOperation("获取用户消息数量")
    public R<MessageCountVo> getUserMessageCount() {
        return R.ok(feedbackMessageService.getUserMessageCount());
    }

    @PostMapping("/getServeMessage")
    @ApiOperation("获取用户客服消息")
    public R<List<ServeMessageVo>> getUserServeMessage() {
        return R.ok(feedbackMessageService.getUserServeMessage());
    }

    @PostMapping("/getLogisticsMessage")
    @ApiOperation("获取用户交易物流消息")
    public R<Page<LogisticsVo>> getLogisticsMessage(@RequestBody UserMessagePo userMessagePo) {
        return R.ok(feedbackMessageService.getLogisticsMessage(userMessagePo));
    }

    @PostMapping("/getNoticeMessage")
    @ApiOperation("获取用户服务通知消息")
    public R<Page<NoticeVo>> getNoticeMessage(@RequestBody UserMessagePo userMessagePo) {
        return R.ok(feedbackMessageService.getNoticeMessage(userMessagePo));
    }

    @GetMapping("/readMessage")
    @ApiOperation("根据商家id修改当前用户未读信息为已读")
    public R<Boolean> readMessage(@RequestParam Long merchantId) {
        return R.ok(feedbackMessageService.readMessage(merchantId));
    }

    @PostMapping("/minePowerStation")
    @ApiOperation(value = "我的电站列表")
    @ApiOperationSupport(order = 8, includeParameters = {
            "powerStationPo.itemName",
            "powerStationPo.pageSize",
            "powerStationPo.totalPage"
    })
    public R<Page<PowerStationVo>> minePowerStation(@RequestBody PowerStationPo powerStationPo) {
        return R.ok(powerStationService.minePowerStation(powerStationPo));
    }

//    @PostMapping("/powerStationInfo")
//    @ApiOperation(value = "电站详情")
//    public R<?> powerStationInfo() {
//        return R.ok();
//    }

    @PostMapping("/addPowerStation")
    @ApiOperation(value = "我的电站-新增项目")
    public R<Boolean> addPowerStation(@RequestBody MinePowerStationPo minePowerStationPo) {
        return R.ok(powerStationService.addPowerStation(minePowerStationPo));
    }

    @GetMapping("/applyTradePowerStation")
    @ApiOperation(value = "申请买卖电站")
    public R<Boolean> applyTradePowerStation(@RequestParam Integer powerStationId) {
        return R.ok(powerStationService.applyTradePowerStation(powerStationId));
    }
}
